var GetData = [];
GetData.server_list = [];// 分发节点列表
GetData.color = ['#F2B701', '#E57D04', '#DC0030', '#B10058', '#7C378A', '#3465AA', 'aqua'];
GetData.server_color = [];//颜色
/****
 * 页面加载完成后执行的函数
 * @returns viod
 */
GetData.init = function () {
    ShowMap.init();
    GetData.getroll();
    GetData.GetNodeList();
    GetData.GetTotalCount();
    GetData.GetTopCity();
};
//详情列表滚动置顶
GetData.getroll = function () {
    $(".detailed_list li:gt(4)").hide();
    var scrtime;
    $(".detailed_list").hover(function () {
        clearInterval(scrtime);
    }, function () {
        scrtime = setInterval(function () {
            var $ul = $(".detailed_list");
            var liHeight = $ul.find("li:last").height();
            $ul.animate({marginTop: liHeight + 35 + "px"}, 0, function () {
                $ul.find("li:last").prependTo($ul);
                $ul.find("li:first").hide();
                $ul.css({marginTop: 0});
                $ul.find("li:first").fadeIn();
                $(".detailed_list li:gt(4)").hide();
            });
        }, 2000);
    }).trigger("mouseleave");
};
//昨,今日总请求数
GetData.GetTotalCount = function () {
    $.getJSON("data/total_count.json", function (data) {
        $('#todayTotal').attr('data-to', data.total_td);
        $('#todayTotal').html(data.total_td);
        $('#yesterday').html(data.total_yd);
        setTimeout(function () {
            GetData.GetTotalCount();
        }, 10000);
    });
};
// 为指定的分发节点设定一个颜色
GetData.setServerColor = function (key) {
    var color_point = GetData.server_color.length;
    while (GetData.color.length < color_point) {
        color_point -= GetData.color.length;
    }
    return GetData.color[color_point];
};
//获取服务器热门节点
GetData.GetNodeList = function () {
    $.getJSON("data/server_list.json", function (data) {
        GetData.server_list = data;
        var li = '';
        for (var key in GetData.server_list) {
            var server = GetData.server_list[key];
            if (!GetData.server_color[key]) {
                GetData.server_color[key] = GetData.setServerColor(key);
                GetData.server_color.length++;
            }
            li += '<li><div class="frequency" style="color:' + GetData.server_color[key] + '">'
                    + server.total + '</div><div class="city" style="color:'
                    + GetData.server_color[key] + '">' + server.name + '</div></li>';
            GetData.ServerClient(key);
        }
        $("#server_list").html(li);
        GetData.GetClientDetel();
        setTimeout(function () {
            GetData.GetNodeList();
        }, 20000);
    });
};
//获取热门城市
GetData.GetTopCity = function () {
    $.getJSON("data/server_city.json", function (data) {
        var list = '';
        for (var city in data) {
            var server_city = data[city];
            list += '<li><div class="color1">'
                    + server_city.total
                    + '</div><div class="city">'
                    + server_city.name + '</div></li>';
        }
        $("#present").html(list);
        setTimeout(function () {
            GetData.GetTopCity();
        }, 10000);
    });
};
// 获取服务器对应的客户端
GetData.ServerClient = function (sid) {
    $.getJSON("data/server_" + sid + ".json", function (data) {
        ShowMap.ShowNode(sid, data);
    });
};
//获取详细列表详细
GetData.GetClientDetel = function () {
    $.getJSON('data/clientInfo.json', function (data) {
        var li = '';
        if (data !== null && data.length !== 0) {
            for (var key in data) {
                if (data[key] === null) {
                    continue;
                }
                var server = GetData.server_list[data[key].server];
                li += '<li style="color:' + GetData.server_color[data[key].server] + '"><div>'
                        + data[key].ip + '</div> <div>'
                        + data[key].timestamp + '</div> <div>'
                        + data[key].country + '</div><div>'
                        + data[key].city + '</div><div>'
                        + ((server) ? server.name : '') + '</div> </li>';
            }
            $(".detailed_list").html(li);
        }
    });
};